package site.jjqzplucky.gateway.service;

import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import java.util.List;

@Component
@RequiredArgsConstructor
public class RedisService {
    private final RedisTemplate<String, Object> redisTemplate;

    public void setValue(String key, Object value) {
        redisTemplate.opsForValue().set(key, value);
    }

    public Object getValue(String key) {
        return redisTemplate.opsForValue().get(key);
    }

    public <T> void  setList(String key, T item){
        redisTemplate.opsForList().rightPush(key, item);
    }

    public <T> void  setList(String key, List<T> list){
        redisTemplate.opsForList().rightPushAll(key, list.toArray());
    }

    public List getList(String key){
        return redisTemplate.opsForList().range(key,0, -1);
    }
}
